<template>
  <div class="detail-logistics" v-if="logistics">
    <p>
      <span>{{ logistics.list[0].text }}</span>
      <span>{{ logistics.list[0].time }}</span>
    </p>
    <a @click="onViewLogisticsButtonClickHandler">查看物流</a>
  </div>
  <teleport to="#modal">
    <OrderLogistics ref="orderLogisticsComponent"></OrderLogistics>
  </teleport>
</template>
<script>
import { useRoute } from "vue-router";
import { getLogisticsByOrderId } from "@/api/member";
import { ref } from "vue";
import OrderLogistics from "@/views/member/order/components/OrderLogistics";
export default {
  name: "DetailLogistics",
  components: { OrderLogistics },
  async setup() {
    // 获取路由信息对象
    const route = useRoute();
    // 用于存储订单物流信息
    const logistics = ref(null);
    // 获取物流信息
    let data = await getLogisticsByOrderId(route.params.id);
    // 存储物流信息
    logistics.value = data.result;
    // 查看物流信息
    // 用于存储物流信息弹层组件实例对象
    const orderLogisticsComponent = ref();
    // 当用户点击查看物流按钮时
    const onViewLogisticsButtonClickHandler = () => {
      // 渲染弹层
      orderLogisticsComponent.value.visible = true;
      // 传递物流信息
      orderLogisticsComponent.value.logistics = logistics.value;
    };
    return {
      logistics,
      onViewLogisticsButtonClickHandler,
      orderLogisticsComponent,
    };
  },
};
</script>
<style scoped lang="less">
.detail-logistics {
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  background-color: #f5f5f5;
  margin: 30px 50px 0;
  > p {
    flex: 1;
    span {
      color: #999;
      &:first-child {
        margin-right: 30px;
      }
    }
  }
  > a {
    color: @xtxColor;
    text-align: center;
  }
}
</style>
